﻿
using System.Data;
using Microsoft.VisualBasic;
using System;
namespace Crystal.CLL
{
    public class BaseClass
    {
        public static string crystalCaption = MessageManager.GetMessage("CRYSTAL");

        #region Methods
        #region "String Helper Methods"

        /// <summary>
        /// Capitalize
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Capitalize(string str)
        {
            string retString = "";
            bool newChar = true;
            for (int i = 0; i <= str.Length - 1; i++)
            {
                if (str[i] == '_')
                {
                    newChar = true;
                }
                else if (newChar)
                {
                    retString += str[i].ToString().ToUpper();
                    newChar = false;
                }
                else
                {
                    retString += str[i].ToString().ToLower();
                }
            }
            return retString;
        }
        /// <summary>
        /// Set spaces between strings
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string SetSpaces(string str)
        {
            string retString = "";
            bool newChar = true;
            for (int i = 0; i <= str.Length - 1; i++)
            {
                if ((int)str[i] >= 65 && (int)str[i] <= 92)
                {
                    newChar = true;
                }
                if (newChar)
                {
                    retString += " " + str[i].ToString().ToUpper();
                    newChar = false;
                }
                else
                {
                    retString += str[i].ToString().ToLower();
                }
            }
            return retString;
        }

        #endregion
        #endregion

        #region "DataReader Read Only"
        public static void ChangeDataReaderDataTable(ref DataTable ChkTable)
        {
            foreach (DataColumn lCol in ChkTable.Columns)
            {
                lCol.ReadOnly = false;
                lCol.AllowDBNull = true;
            }
        }
        #endregion

        #region "Validation String"
        public static bool CheckNumeric(char val)
        {
            // Try
            if (val == '.')
                return true;
            if (val == '-')
                return true;
            if (Strings.Asc(val) == 8)
                return true;
            if (char.IsDigit(val) == false)
            {
                return false;
            }
            else
            {
                return true;
            }

        }

        public static bool CheckNumericString(string val)
        {
            if (Strings.Asc(val) == 8)
                return true;
            if (Information.IsNumeric(val) == false)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        #endregion

        #region "Add Blank Row To data Table atLast"
        public static DataTable BlankRowAtLastDataTable(DataTable dtable)
        {
            DataRow drow = dtable.NewRow();
            drow.ItemArray[0] = DBNull.Value;
            dtable.Rows.Add(drow);
            return dtable;
        }
        public static DataTable InsertRowAtLastDataTable(DataTable dtable, string value, string column)
        {
            //int count = dtable.Rows.Count;
            DataRow drow = dtable.NewRow();
            drow[column] = value.ToString();
            dtable.Rows.InsertAt(drow, 0);
            return dtable;
        }
        #endregion

    }
}
